package com.exam.controller;

import com.exam.dto.ActionResult;
import com.exam.po.Score;
import com.exam.service.UStudentService;
import com.exam.ustudent.UStudent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhanghui
 * @ClassName UStudentController
 * @Description TODO
 * @Date 2021/1/12 11:08
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api")
public class UStudentController {
    @Autowired
    private UStudentService uStudentService;
    /**
     * @Author zhanghui
     * @Description ;老师查看学生成绩
     * @Date 2021/1/13 10:44
     * @Param [teacherId, page, size]
     * @return com.exam.dto.ActionResult
     **/
    @GetMapping("/uStudents/checkStudentScore/{teacherId}/{page}/{size}")
    public ActionResult checkStudentScore(@PathVariable Integer teacherId, @PathVariable Integer page, @PathVariable Integer size){
        Map<String,Object> map = new HashMap<>();
        Integer total = uStudentService.findStudentScoreCount(teacherId);
        List<UStudent> res = uStudentService.findStudentScore(teacherId,page,size);
        map.put("total",total);
        map.put("data",res);
        if(map!=null){
            return new ActionResult(200,"查询成功",map);
        }
        return new ActionResult(400,"查询失败",null);
    }
    /**
     * @Author zhanghui
     * @Description 修改成绩表状态
     * @Date 2021/1/14 11:50
     * @Param [score]
     * @return com.exam.dto.ActionResult
     **/
    @PutMapping("/uStudents/updateScoreStatus")
    public ActionResult updateScoreStatus(@RequestBody Score score ){
        if(uStudentService.updateScoreStatus(score)>0){
            return new ActionResult(200,"修改成功",null);
        }
        return new ActionResult(400,"修改失败",null);
    }
}
